package com.erp.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.shop.domain.bo.ErpSellerStoreSubcategoryBo;
import com.erp.shop.domain.vo.ErpSellerStoreSubcategoryVo;
import com.erp.shop.service.IErpSellerStoreSubcategoryService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 卖家店铺所在类目
 *
 * @author erp
 * @date 2023-05-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/sellerStoreSubcategory")
public class ErpSellerStoreSubcategoryController extends BaseController {

    private final IErpSellerStoreSubcategoryService iErpSellerStoreSubcategoryService;

    /**
     * 根据发布类目id、父属性路径（可选）获取子属性信息，只返回有权限品牌
     */
    @GetMapping("/getChildAttributesResultByPostCateIdAndPath")
    public R<Object> getChildAttributesResultByPostCateIdAndPath(String param1, Long storeId) {
        return iErpSellerStoreSubcategoryService.getChildAttributesResultByPostCateIdAndPath(param1, storeId);
    }


    /**
     * 获取该店铺所拥有的的分类
     */
    @GetMapping("/queryStoreSubCategory")
    public R<String> queryStoreSubCategory(Long sellerId) {
        return iErpSellerStoreSubcategoryService.queryStoreSubCategory(sellerId);
    }

    /**
     * 获取该店铺所拥有的的分类
     */
    @GetMapping("/querySubCategoryListByStoreId")
    public R<Object> querySubCategoryListByStoreId(Long storeId) {
        return iErpSellerStoreSubcategoryService.querySubCategoryListByStoreId(storeId);
    }

    /**
     * 用户选择店铺分类
     */
    @PostMapping("/chooseStoreSubCategory")
    public R<String> chooseStoreSubCategory(@RequestBody ErpSellerStoreSubcategoryBo bo) {
        return iErpSellerStoreSubcategoryService.chooseStoreSubCategory(bo);
    }

    /**
     * 查询卖家店铺所在类目列表
     */
    @SaCheckPermission("system:sellerStoreSubcategory:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreSubcategoryVo> list(ErpSellerStoreSubcategoryBo bo, PageQuery pageQuery) {
        return iErpSellerStoreSubcategoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出卖家店铺所在类目列表
     */
    @SaCheckPermission("system:sellerStoreSubcategory:export")
    @Log(title = "卖家店铺所在类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSellerStoreSubcategoryBo bo, HttpServletResponse response) {
        List<ErpSellerStoreSubcategoryVo> list = iErpSellerStoreSubcategoryService.queryList(bo);
//        ExcelUtil.exportExcel(list, "卖家店铺所在类目", ErpSellerStoreSubcategoryVo.class, response);
    }

    /**
     * 获取卖家店铺所在类目详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:sellerStoreSubcategory:query")
    @GetMapping("/{id}")
    public R<ErpSellerStoreSubcategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable Long id) {
        return R.ok(iErpSellerStoreSubcategoryService.queryById(id));
    }

    /**
     * 获取卖家店铺所在类目详细信息
     *
     */
    @SaCheckPermission("system:sellerStoreSubcategory:getSubcategoryByStoreIdAndCategoryId")
    @GetMapping("/getSubcategoryByStoreIdAndCategoryId/{storeId}/{categoryId}")
    R<Object> getSubcategoryByStoreIdAndCategoryId(@PathVariable("storeId") Long storeId, @PathVariable("categoryId") Long categoryId) {
        return iErpSellerStoreSubcategoryService.getSubcategoryByStoreIdAndCategoryId(storeId,categoryId);
    }

    /**
     * 新增卖家店铺所在类目
     */
    @SaCheckPermission("system:sellerStoreSubcategory:add")
    @Log(title = "卖家店铺所在类目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreSubcategoryBo bo) {
        return toAjax(iErpSellerStoreSubcategoryService.insertByBo(bo));
    }

    /**
     * 修改卖家店铺所在类目
     */
    @SaCheckPermission("system:sellerStoreSubcategory:edit")
    @Log(title = "卖家店铺所在类目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreSubcategoryBo bo) {
        return toAjax(iErpSellerStoreSubcategoryService.updateByBo(bo));
    }

    /**
     * 删除卖家店铺所在类目
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:sellerStoreSubcategory:remove")
    @Log(title = "卖家店铺所在类目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreSubcategoryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
